package res
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;

	public class DefaultResManager
	{
		private static var _arrNumberBitmapData:Array; 
		public static function initialize():void
		{
			_arrNumberBitmapData = new Array();
			var t:TextField = new TextField();
			t.textColor = 0xff0000;
			var bitmapData:BitmapData;
			for( var i:int=0; i<10; i++ )
			{
				t.text = i.toString();
				t.width = t.textWidth + 4;
				t.height = t.textHeight + 4;
				bitmapData = new BitmapData( t.width, t.height, true, 0 );
				bitmapData.draw( t );
				_arrNumberBitmapData.push( bitmapData );
			}
		}
		
		public static function getNumberDisplay( value:int ):Sprite
		{
			var s:Sprite = new Sprite();
			var n:int;
			while(true)
			{
				n = value % 10;
				s.addChild( new Bitmap(_arrNumberBitmapData[n]) );
				if( value==n ) break;
				value /= 10;
			}
			n = s.numChildren;
			var w:int = 0;
			var dis:DisplayObject;
			for( var i:int=n-1; i>=0; i-- )
			{
				dis = s.getChildAt(i);
				dis.x = w;
				w += dis.width;
				w -= 4;
			}
			return s; 
		}
		
		private static var _arrowData:BitmapData;
		public static function get defaultArrowData():BitmapData
		{
			if( _arrowData==null )
			{
				_arrowData = new ArrowPanel();
			}
			return _arrowData;
		}
		
		private static var _cannonballData:BitmapData;
		public static function get defaultCannonballData():BitmapData
		{
			if( _cannonballData==null )
			{
				_cannonballData = new CannonballPanel();
			}
			return _cannonballData;
		}
		
		/**
		 * 默认血条 
		 */		
		private static var _bloodBar:BitmapData;
		public static function get defaultBloodBar():BitmapData
		{
			if( _bloodBar==null )
			{
				_bloodBar = new BitmapData( 50, 4, true, 0xffff0000 );
			}
			return _bloodBar;
		}
		
		/**
		 * 默认血条 框
		 */		
		private static var _bloodBarRect:BitmapData;
		public static function get defaultBloodBarRect():BitmapData
		{
			if( _bloodBarRect==null )
			{
				var rect:Shape = new Shape();
				rect.graphics.lineStyle( 0.1, 0, 1 );
				rect.graphics.drawRect( 0, 0, defaultBloodBar.width, defaultBloodBar.height );
				rect.cacheAsBitmap = true;
				_bloodBarRect = new BitmapData( defaultBloodBar.width, defaultBloodBar.height, true, 0 );
				_bloodBarRect.draw( rect );
			}
			return _bloodBarRect;
		}
		
		public function DefaultResManager()
		{
		}
	}
}



